Going to Map Rs's onto BGC2 Cats.


In [15]:
from os.path import join
from csv import DictReader, DictWriter

In [16]:
fieldnames = '#ID DescID M200b Vmax Vrms R200b Rs Np X Y Z VX VY VZ Parent_ID'.split(' ')
missed_keys = dict() for cosmo_idx in xrange(40): halodir = '/u/ki/swmclau2/des/NewAemulusBoxes/Box%03d/halos/m200b/'%cosmo_idx #halodir = '/home/users/swmclau2/scratch/NewTrainingBoxes/Box%03d/halos/m200b/'%cosmo_idx #halodir = '/home/users/swmclau2/scratch/TrainingBoxes/Box000/halos/m200b/' #halodir = '/home/users/swmclau2/scratch/TestBoxes/TestBox000-000/halos/m200b/' for snapshot_idx in xrange(10): outlist_fname = join(halodir, "out_%d.list"%snapshot_idx) bgc2list_fname = join(halodir, "outbgc2_%d.list"%snapshot_idx) bgc2list_fname2 = join(halodir, "outbgc2_rs_%d.list"%snapshot_idx) print cosmo_idx, snapshot_idx outlist_rs = dict() with open(outlist_fname) as csvfile: reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ') for row in reader: outlist_rs[row['#ID']] = row['Rs'] with open(bgc2list_fname) as oldfile, open(bgc2list_fname2, 'w') as newfile: reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', oldfile), delimiter = ' ') #writer = DictWriter(newfile, fieldnames, delimiter = ' ') #writer.writeheader() for row in reader: try: row['Rs'] = outlist_rs[row['#ID']] except KeyError: missed_keys[cosmo_idx] = row['#ID'] #writer.writerow(row) break

In [17]:
missed_keys = dict()
cosmo_idx = 0
halodir = '/u/ki/swmclau2/des/NewAemulusBoxes/Box%03d/halos/m200b/'%cosmo_idx
#halodir = '/home/users/swmclau2/scratch/NewTrainingBoxes/Box%03d/halos/m200b/'%cosmo_idx
#halodir = '/home/users/swmclau2/scratch/TrainingBoxes/Box000/halos/m200b/'
#halodir = '/home/users/swmclau2/scratch/TestBoxes/TestBox000-000/halos/m200b/'
#for snapshot_idx in xrange(10):
snapshot_idx = 2

outlist_fname = join(halodir, "out_%d.list"%snapshot_idx)
bgc2list_fname = join(halodir, "outbgc2_%d.list"%snapshot_idx)
bgc2list_fname2 = join(halodir, "outbgc2_rs_%d.list"%snapshot_idx)

print (cosmo_idx, snapshot_idx),

outlist_idxs = set()
with open(outlist_fname) as csvfile:
    reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ')
    for row in reader:
        #outlist_rs[row['#ID']] = row['Rs']
        outlist_idxs.add(int(row['#ID']))

bgc2_idxs = set()
with open(bgc2list_fname) as oldfile, open(bgc2list_fname2, 'r') as newfile:
    reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', newfile), delimiter = ' ')
    #writer = DictWriter(newfile, fieldnames, delimiter = ' ')
    #writer.writeheader()

    for row in reader:
        bgc2_idxs.add(int(row['#ID']) )
        #try:
        #    row['Rs'] = outlist_rs[row['#ID']]
        #except KeyError:
        #    missed_keys[cosmo_idx] = row['#ID']

        #writer.writerow(row)
print len(bgc2_idxs - outlist_idxs), len(outlist_idxs - bgc2_idxs)


(0, 2) 50 0

In [18]:
print bgc2_idxs - outlist_idxs


set([8836805, 8836806, 8836807, 8836808, 8836809, 8836810, 8836811, 8836812, 8836813, 8836814, 8836815, 8836816, 8836817, 8836818, 8836819, 8836820, 8836821, 8836822, 8836823, 8836824, 8836825, 8836826, 8836827, 8836828, 8836829, 8836830, 8836831, 8836832, 8836833, 8836834, 8836835, 8836836, 8836837, 8836838, 8836839, 8836840, 8836841, 8836842, 8836843, 8836844, 8836845, 8836846, 8836847, 8836848, 8836849, 8836850, 8836851, 8836852, 8836853, 8836854])
(0, 0) 0 0 (0, 1) 528 0 (0, 2) 50 0 (0, 3) 2 0 (0, 4) 0 639 (0, 5) 0 794 (0, 6) 39 0 (0, 7) 2 0 (0, 8) 0 617 (0, 9) 0 636

In [19]:
bgc2list_rs = dict()
bgc2_zero_rs = set()
with open(bgc2list_fname2) as csvfile:
    reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ')
    for row in reader:
        bgc2list_rs[int(row['#ID'])] = float(row['Rs'])
        if float(row['Rs']) <= 0:
            bgc2_zero_rs.add(int(row['#ID']) )
            #print row

print len(zero_rs)


31219

In [20]:
outlist_rs = dict()
outlist_zero_rs = set()
with open(outlist_fname) as csvfile:
    reader = DictReader(filter(lambda row: row[0]!='#' or row[:3]=='#ID', csvfile), delimiter = ' ')
    for row in reader:
        outlist_rs[int(row['#ID'])] = float(row['Rs'])
        if float(row['Rs']) <= 0:
            outlist_zero_rs.add(int(row['#ID']) )
            #print row

print len(zero_rs)


31219
rs_file_keys = set(outlist_rs.keys())

In [21]:
outlist_counter = 0
bgc2_counter = 0
for key in outlist_zero_rs:
    if key in outlist_idxs:
        outlist_counter+=1
    if key in bgc2_idxs:
        bgc2_counter+=1
        
print outlist_counter, bgc2_counter


18827 18827

In [22]:
print_counter = 0
for idx, rs in outlist_rs.iteritems():
    if rs == 0:
        print idx,
        print_counter+=1
        
    if print_counter > 50:
        break


826 2162 7304 22752 32758 47021 47292 55384 55603 57918 58808 60356 62380 64054 65571 66618 66728 67060 68249 68344 69395 69646 70193 70699 71703 71721 72697 72842 73014 73453 73476 73925 74734 74774 75820 76266 76438 76919 77782 77960 78180 78512 79038 79116 79500 80286 81118 81193 81734 81885 82382

In [23]:
outlist_counter = 0
bgc2_counter = 0
for key in bgc2_zero_rs:
    if key in outlist_idxs:
        outlist_counter+=1
    if key in bgc2_idxs:
        bgc2_counter+=1
        
print outlist_counter, bgc2_counter


18827 18877

In [24]:
for key in zero_rs


  File "<ipython-input-24-52c990ed79ee>", line 1
    for key in zero_rs
                      ^
SyntaxError: invalid syntax

In [ ]:
outlist_rs.values()

In [ ]:
import numpy as np
rs_arr = np.array(list(outlist_rs.itervalues())).astype(float)

In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline

In [ ]:
n_zero_rs = np.sum(rs_arr == 0)
print n_zero_rs, n_zero_rs*1.0/rs_arr.shape[0]

In [ ]:
plt.hist(rs_arr)

In [ ]: